<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});


Route::namespace('Api')->group(function () {
    // 需要用户信息的
    Route::get('/wxlogin','AuthorizationController@wxLogin');
    Route::middleware('auth:api')->group(function () {
        Route::post('products/{product}/favorite', 'ProductsController@favor')->name('products.favor');//添加收藏
        Route::delete('products/{product}/favorite', 'ProductsController@disfavor')->name('products.disfavor');//取消收藏
        Route::get('products/favorites', 'ProductsController@favorites')->name('products.favorites');//收藏列表
        Route::get('cart', 'CartController@index')->name('cart.index');//查看购物车
        Route::post('cart/add', 'CartController@add')->name('cart.add');//增加购物车数量
        Route::post('cart/increase', 'CartController@increase')->name('cart.increase');//减少购物车
        Route::post('cart/decrease', 'CartController@decrease')->name('cart.decrease');//减少购物车
        Route::delete('cart', 'CartController@remove')->name('cart.remove');//删除购物车
        Route::get('addresses', 'UserAddressesController@index')->name('user.get_addresses');//查看收货地址
        Route::get('address_by_id', 'UserAddressesController@addresById');//查看收货地址
        Route::post('addresses/setdefault', 'UserAddressesController@setDefault');//设置成默认地址
        Route::post('addresses', 'UserAddressesController@store');//新增收货地址
        Route::put('addresses/{id}', 'UserAddressesController@update');//更新收货地址
        Route::delete('addresses/{id}', 'UserAddressesController@destroy');//删除地址
        Route::get('orders','OrdersController@index');//所有订单
        Route::get('order','OrdersController@getOrder');//单个订单
        Route::post('order/create','OrdersController@store');//创建订单
        Route::post('order/repay','OrdersController@rePay');//重新支付订单
        Route::delete('order/{id}', 'OrdersController@destroy');//删除订单
        Route::post('orders/{order}/apply_refund', 'OrdersController@applyRefund')->name('orders.apply_refund');//申请退款
        Route::post('orders/{order}/received', 'OrdersController@received')->name('orders.received');//确认收货
        Route::get('/product_favor/{product}','ProductsController@isFavored');
    });


    Route::get('/launch','IndexController@appLaunch');
    Route::get('/about','IndexController@about');
    Route::get('/index','IndexController@index');
    Route::get('/categories','CategoriesController@index');
    Route::get('/products','ProductsController@index');
    Route::get('/products/sku','ProductsController@getSku');
    Route::get('/products/getskubyid','ProductsController@getSkuById');
    Route::get('/product/{product}','ProductsController@detail');
    Route::post('/get_products_bycategory','ProductsController@getProductsBycategory');
    Route::get('/searchrecords','SearchRecordsController@index');
    Route::post('/search','SearchRecordsController@search');

    //微信支付回调
    Route::any('/pay/wxpaynotify','WxPayController@WxPayNotify')->name('pay.wxpaynotify');
});